import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function main() {
  await prisma.$executeRaw`delete from "User" `;
  await prisma.$executeRaw`delete from "Post" `;
  //   await prisma.post.deleteMany();
  const user1 = await prisma.user.create({
    data: {
      name: "Alice",
      email: "alice@example.com",
    },
  });
  console.log("Created user1 with ", user1);
  const user2 = await prisma.user.create({
    data: {
      name: "Bob",
      email: "bob@example.com",
    },
  });

  console.log("Created user with ", user2);

  const post1 = await prisma.post.create({
    data: {
      title: "Hello World",
      content: "This is my first post!",
      published: true,
      author: {
        connect: { id: user1.id }, // 关联用户Alice
      },
    },
  });
  console.log("Created post:", post1);

  const post2 = await prisma.post.create({
    data: {
      title: "Prisma is awesome",
      content: "Learning more about Prisma.",
      published: false,
      authorId: user2.id, // 另一种关联方式，直接使用外键
    },
  });
  console.log("Created post:", post2);
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
